<template>
  <div class="goods-hot">
    <!-- 19.2步骤3里的写的 表达式一种方法 -->
    <!-- <h3>{{ type === 1 ? "24小时" : "周" }}榜</h3> -->
    <!-- 19.2步骤5里另一种写法，当多的时候 -->
    <h3>{{ TYPE[type] }}</h3>
    <!-- 商品区块 -->
    <RouterLink
      v-for="item in hotList"
      :key="item.id"
      to="/"
      class="goods-item"
    >
      <img :src="item.picture" alt="" />
      <p class="name ellipsis">{{ item.desc }}</p>
      <p class="desc ellipsis">{{ item.name }}</p>
      <p class="price">&yen;{{ item.price }}</p>
    </RouterLink>
  </div>
</template>
<script>
import { findHotGoods } from '@/api/good.js'
import { ref } from 'vue'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  props: {
    type: {
      type: Number
    }
  },
  setup (props) {
    // 前端枚举
    const TYPE = {
      1: '24小时热榜',
      2: '周榜',
      3: '年榜'
    }
    //  <!-- 24热榜+专题推荐 -->
    const hotList = ref([])
    const route = useRoute()
    async function findHotGoodsList () {
      const res = await findHotGoods({
        id: route.params.id,
        // 判断这个type，让父组件定义传到这里来，接收参数
        type: props.type.type
      })
      hotList.value = res.result
    }
    findHotGoodsList()
    return {
      hotList,
      TYPE
    }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;
    img {
      width: 160px;
      height: 160px;
    }
    p {
      padding-top: 10px;
    }
    .name {
      font-size: 16px;
    }
    .desc {
      color: #999;
      height: 29px;
    }
    .price {
      color: @priceColor;
      font-size: 20px;
    }
  }
}
</style>
